package app

import (
	"encoding/json"
)

func ConvertData[T any](a interface{}) (T, error) {
	var (
		data T
	)
	jsonBytes, _ := json.Marshal(a)
	err := json.Unmarshal(jsonBytes, &data)
	if err != nil {
		return data, err
	}
	return data, nil
}

func ConvertDataByArr[T any](a interface{}) ([]T, error) {
	var (
		datas []T
	)
	jsonBytes, _ := json.Marshal(a)
	err := json.Unmarshal(jsonBytes, &datas)
	if err != nil {
		return datas, err
	}
	return datas, nil
}
